package cn.game.tanke.util;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;

public class TankMap {
    public static Image grass;
    public static Image wall;
    public static Image water;
    public static Image steel;
    public static Image ice;
    public static Image boss;
    public static Image enemy;
    public static Image player;
    public static Image bullet;
    public static Image boom;
    public static Image gameOver;
    static {
        try {
            grass = ImageIO.read(TankMap.class.getClassLoader().getResourceAsStream("images/grass.png"));
            wall = ImageIO.read(TankMap.class.getClassLoader().getResourceAsStream("images/wall.gif"));
            water = ImageIO.read(TankMap.class.getClassLoader().getResourceAsStream("images/water.png"));
            steel = ImageIO.read(TankMap.class.getClassLoader().getResourceAsStream("images/steels.png"));
            ice = ImageIO.read(TankMap.class.getClassLoader().getResourceAsStream("images/ice.png"));
            boss = ImageIO.read(TankMap.class.getClassLoader().getResourceAsStream("images/boss.gif"));
            enemy = ImageIO.read(TankMap.class.getClassLoader().getResourceAsStream("images/enemy.png"));
            player = ImageIO.read(TankMap.class.getClassLoader().getResourceAsStream("images/player.gif"));
            bullet = ImageIO.read(TankMap.class.getClassLoader().getResourceAsStream("images/bullet.png"));
            boom = ImageIO.read(TankMap.class.getClassLoader().getResourceAsStream("images/boom.png"));
            gameOver=ImageIO.read(TankMap.class.getClassLoader().getResourceAsStream("images/gameOver.jpg"));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    public final static int[][] MAPARRAY={
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,6,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0},
            {0,2,2,2,2,2,2,1,1,1,1,1,1,3,3,3,3,1,1,1,1,1,1,4,4,1,1,1,1,0},
            {0,2,2,2,2,2,2,1,1,3,3,1,1,3,3,3,3,1,3,3,1,1,1,4,4,1,1,1,1,0},
            {0,2,2,2,2,2,2,1,1,3,3,1,1,3,3,3,3,1,3,3,1,1,1,4,4,1,1,1,1,0},
            {0,2,2,6,6,1,1,1,1,3,3,1,1,1,4,4,1,1,3,3,1,1,1,1,1,1,1,1,1,0},
            {0,2,2,6,6,1,4,4,1,3,3,1,1,1,4,4,1,1,3,3,1,1,1,6,6,6,6,1,1,0},
            {0,2,2,6,6,1,4,4,1,1,1,1,1,1,4,4,1,1,1,1,1,1,1,6,6,6,6,1,1,0},
            {0,1,1,5,5,1,1,1,2,2,2,2,2,2,2,1,1,1,1,5,5,2,2,2,2,2,2,3,3,0},
            {0,1,1,5,5,1,1,3,3,3,3,4,4,3,3,3,3,1,1,5,5,2,2,2,2,2,2,3,3,0},
            {0,1,1,5,5,1,1,3,3,3,3,4,4,3,3,3,3,1,1,5,5,5,5,5,5,5,5,3,3,0},
            {0,1,1,5,5,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,3,3,1,1,2,2,2,1,1,0},
            {0,1,1,3,3,1,1,2,2,2,1,1,1,1,1,1,1,1,1,3,3,3,1,1,2,2,2,1,1,0},
            {0,1,1,3,3,1,1,2,2,2,1,4,4,4,4,4,4,4,1,3,3,3,1,1,2,2,2,1,1,0},
            {0,4,3,3,4,4,1,1,1,1,1,1,1,1,4,1,1,1,1,1,1,1,1,1,2,2,2,1,1,0},
            {0,1,3,3,2,2,1,3,3,1,1,1,1,1,4,1,1,1,3,3,3,2,2,3,3,3,4,4,4,0},
            {0,1,3,3,2,2,1,3,3,3,1,3,3,1,1,1,1,1,3,3,3,2,2,3,3,3,4,4,4,0},
            {0,1,3,3,2,2,1,3,3,3,1,3,1,1,1,1,1,1,1,1,1,1,1,1,3,3,1,1,1,0},
            {0,1,3,3,2,2,1,3,3,1,1,1,3,3,3,3,3,3,1,1,1,1,1,1,3,3,1,1,1,0},
            {0,1,3,3,2,2,1,3,3,1,1,1,3,1,1,1,1,3,1,1,1,1,1,1,3,3,1,1,1,0},
            {0,1,3,3,4,4,1,1,1,1,1,1,3,1,7,1,1,3,1,1,1,1,1,1,3,3,1,1,1,0},
            {0,1,3,3,4,4,1,1,1,1,1,1,3,1,1,1,1,3,1,1,1,1,1,1,3,3,1,1,1,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
    };
    public static void drawMap(Graphics graphics, JPanel jPanel) {
        //在哪里画以及画什么（在具体的某个位置绘制某个东西）
        for (int y = 0; y< MAPARRAY.length; y++) {
            for (int x = 0; x < MAPARRAY[y].length; x++){
                switch (MAPARRAY[y][x]){
//
                    case 3:
                        graphics.drawImage(wall,x*32,y*32,(x+1)*32,(y+1)*32,0,0,60,60,jPanel);
                        break;
                    case 2:
                        graphics.drawImage(grass,x*32,y*32,(x+1)*32,(y+1)*32,0,0,87,83,jPanel);
                        break;
                    case 4:
                        graphics.drawImage(ice,x*32,y*32,(x+1)*32,(y+1)*32,0,0,64,64,jPanel);
                        break;
                    case 5:
                        graphics.drawImage(water,x*32,y*32,(x+1)*32,(y+1)*32,0,0,52,65,jPanel);
                        break;
                    case 6:
                        graphics.drawImage(steel,x*32,y*32,(x+1)*32,(y+1)*32,0,0,32,32,jPanel);
                        break;
                }
            }
        }
    }

}
